<?php

/**
 * This is the model class for table "user".
 *
 * The followings are the available columns in table 'user':
 * @property integer $user_ID
 * @property string $username
 * @property string $password
 * @property integer $active
 * @property integer $level
 * @property integer $user_data_ID
 *
 * The followings are the available model relations:
 * @property Comment[] $comments
 * @property Group[] $groups
 * @property GroupData[] $groupDatas
 * @property Option[] $options
 * @property Share[] $shares
 * @property Subscribe[] $subscribes
 * @property Subscribe[] $subscribes1
 * @property Upload[] $uploads
 * @property UserData $userData
 */
class User extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return User the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'user';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('username', 'length', 'max'=>45),
			array('password', 'length', 'max'=>8),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('user_ID, username, password, active, level, user_data_ID', 'safe', 'on'=>'search'),
			
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'comments' => array(self::HAS_MANY, 'Comment', 'author_ID'),
			'groups' => array(self::MANY_MANY, 'Group', 'user_has_group(user_ID, group_ID)'),
			'groupDatas' => array(self::HAS_MANY, 'GroupData', 'leader_ID'),
			'options' => array(self::HAS_MANY, 'Option', 'user_ID'),
			'shares' => array(self::HAS_MANY, 'Share', 'sharer_ID'),
			'subscribes' => array(self::HAS_MANY, 'Subscribe', 'provider_ID'),
			'subscribes1' => array(self::HAS_MANY, 'Subscribe', 'subscriber_ID'),
			'uploads' => array(self::HAS_MANY, 'Upload', 'uploader_ID'),
			'userData' => array(self::BELONGS_TO, 'UserData', 'user_data_ID'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'user_ID' => 'User',
			'username' => 'Username',
			'password' => 'Password',
			'active' => 'Active',
			'level' => 'Level',
			'user_data_ID' => 'User Data',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('user_ID',$this->user_ID);
		$criteria->compare('username',$this->username,true);
		$criteria->compare('password',$this->password,true);
		$criteria->compare('active',$this->active);
		$criteria->compare('level',$this->level);
		$criteria->compare('user_data_ID',$this->user_data_ID);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}